import { createRouter, createWebHashHistory } from "vue-router";
const route = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      component: () => import("@/path/login/index.vue"),
    },
    {
      path: "/index",
      component: () => import("@/path/index/index.vue"),
      children: [
        {
          path: "",
          component: () => import("@/path/view/index.vue"),
        },
        {
          path: "zhsj",
          component: () => import("@/path/zhsj/index.vue"),
        },
        {
          path: "zhyh",
          component: () => import("@/path/zhyh/index.vue"),
        },
        {
          path: "ddyh",
          component: () => import("@/path/ddyh/index.vue"),
        },
        {
          path: "cp",
          component: () => import("@/path/cp/index.vue"),
        },
        {
          path: "userbander",
          component: () => import("@/path/bander/index.vue"),
        },
        {
          path: "ctrl",
          component: () => import("@/path/video/index.vue"),
        },
        {
          path: "shopshow",
          name: "shopshow",
          component: () => import("@/path/shopshow/index.vue"),
        },
      ],
    },
  ],
});
route.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    next();
  } else {
    const token = localStorage.getItem("token");
    if (token) {
      next();
    } else {
      next("/login");
    }
  }
});
export default route;
